package org.lds.scheduled.job.worker.loadbalancer;

import org.lds.scheduled.job.common.model.AppInstanceModel;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class RoundAppInstanceLoadBalancer implements AppInstanceLoadBalancer {
    private AtomicInteger count = new AtomicInteger(0);

    @Override
    public String getAppInstance(List<AppInstanceModel> appInstances) {
        int index = count.getAndIncrement() % appInstances.size();
        return appInstances.get(index).getAddress();
    }
}
